import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { InfoService } from './info.service';
import { CreateInfoDto, BaseInfoDto, UpdateInfoDto, QueryInfoDto, ListInfoDto } from './dto/info.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('儿童信息表，存储孩子的基本信息和账号信息')
@Controller('system/info')
export class InfoController {
  constructor(private readonly infoService: InfoService) {}

  @ApiOperation({ summary: '儿童信息表，存储孩子的基本信息和账号信息-创建' })
  @ApiDataResponse(BaseInfoDto)
  // @RequirePermission('system:info:add')
  @Post()
  create(@Body() body: CreateInfoDto) {
    return this.infoService.create(body);
  }

  @ApiOperation({ summary: '儿童信息表，存储孩子的基本信息和账号信息-列表' })
  @ApiDataResponse(ListInfoDto, true, true)
  // @RequirePermission('system:info:list')
  @Get('list')
  findAll(@Query() query: QueryInfoDto) {
    return this.infoService.findAll(query);
  }

  @ApiOperation({ summary: '我的孩子列表' })
  @ApiDataResponse(ListInfoDto, true, true)
  // @RequirePermission('system:info:list')
  @Get('myChildList/:userId')
  myChildList(@Param('userId') userId: number) {
    return this.infoService.myChildList(userId);
  }

  @ApiOperation({ summary: '检查会员是否过期' })
  @Get('/checkAndUpdateExpiredMembers')
  checkAndUpdateExpiredMembers() {
    return this.infoService.checkAndUpdateExpiredMembers();
  }

  @ApiOperation({ summary: '检查即将过期会员的家长手机号' })
  @Get('/findExpiringMembers')
  findExpiringMembers() {
    return this.infoService.findExpiringMembers();
  }

  @ApiOperation({ summary: '儿童信息表，存储孩子的基本信息和账号信息-详情' })
  @ApiDataResponse(BaseInfoDto)
  // @RequirePermission('system:info:query')
  @Get(':userId')
  findOne(@Param('userId') userId: number) {
    return this.infoService.findOne(userId);
  }

  @ApiOperation({ summary: '儿童信息表，存储孩子的基本信息和账号信息-修改' })
  @ApiDataResponse()
  // @RequirePermission('system:info:edit')
  @Put()
  update(@Body() body: UpdateInfoDto) {
    return this.infoService.update(body);
  }

  @ApiOperation({ summary: '儿童信息表，存储孩子的基本信息和账号信息-删除' })
  @ApiDataResponse()
  // @RequirePermission('system:info:remove')
  @Delete(':userId')
  remove(@Param('userId') userId: number) {
    return this.infoService.remove(userId);
  }
}
